package shapewar.engine.ext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeSet;

import android.widget.Toast;
import shapewar.activities.FrameActivity;
import shapewar.engine.presenter.Presenter;
import shapewar.net.client.User;
import shapewar.view.indvidul.ArrangeListView;

public class Arranger {
	private Presenter pst;
	List<User> list = new ArrayList<User>();
	ArrangeListView alv;
	public Arranger(Presenter pst){
		this.pst = pst;
		pst.ect.arranger = this;
		alv = new ArrangeListView(pst);
		alv.init();
	}
	
	public void update(){
		list.clear();
		Iterator<Entry<Integer,User>> it = pst.ect.client.room.getList();
		while(it.hasNext()){
			list.add(it.next().getValue());
		}
		Collections.sort(list, new Comparator<User>() {
			@Override
			public int compare(User o1, User o2) {
				int a = o1.info.killNum*2-o1.info.dieNum;
				int b = o2.info.killNum*2-o2.info.dieNum;
				return b-a;
			}
		});
		alv.bringToFront();
		alv.invalidate();
	}
	
	public Iterator<User> getIterator(){
		return list.iterator();
	}
}
